package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IHealthDao;
import com.hy.erp.inventory.pojo.Health;
import com.hy.erp.inventory.pojo.interfaces.IHealth;
import com.hy.erp.inventory.service.interfaces.IHealthService;

@ Name ( "healthService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class HealthService extends AbstractBusinessService < IHealth> implements IHealthService{

	@Override
	public String[] addHealth(Object[] health) {


		if ( null == health)
		{
			return null ;
		}
		
		else
		{
		
			IHealthDao healthDao =
			                       ( IHealthDao ) this
			                                          .getDao ( IHealth.class ) ;

			Health[] healths=new Health[health.length];
						for(int i=0;i<health.length;i++)
						{
							Health health2=( Health ) health[i];
							healths[i]=health2;
						}
						return healthDao
						                .persist ( healths ) ;
			
		}
		
	
	
	
	
	
	
	
	
	}

	@Override
	public boolean modifyHealth(IHealth health) {








		if ( ( null == health )
			     || ( null == health
			                                .getIdentifier ( ) )
			     || ( health
			                        .getIdentifier ( )
			                        .trim ( )
			                        .length ( ) == 0 ) )
			{
				return true ;
			}
			else
			{


				IHealthDao healthDao =
				                       ( IHealthDao ) this
				                                          .getDao ( IHealth.class ) ;
				
		
					
				if ( null == health )
				{
					throw new ArchitectureFoundationException  (
					                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
				}
				
				
				return (healthDao
				                  .merge ( health ) != null ) ;
			}
		
	
	
	
	
	
	
	
	
	}

	@Override
	public Integer removeHealth(String[] healthIds) {








		if ( ( null == healthIds)
			     || ( healthIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{




				IHealthDao healthDao =
                    ( IHealthDao ) this
                                       .getDao ( IHealth.class ) ;
		

				return healthDao
				                .remove ( healthIds ) ;
			}
	
	
	
	
	
	
	
	
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public List < IHealth > getHealthById (
											String [ ] Id )
	{
		if((Id.length!=0)||(Id!=null))
		{
			IHealthDao healthDao =
                ( IHealthDao ) this
                                   .getDao ( IHealth.class ) ;
			return healthDao.findByIdentifier ( Id );
		}
		return null ;
	}

	@ Override
	public List < IHealth > getAllHealth ( )
	{
		IHealthDao healthDao =
            ( IHealthDao ) this
                               .getDao ( IHealth.class ) ;


		return healthDao
		                .find ( );
	}

	@ Override
	public List < IHealth > getHealthByQueryName (
													String queryName ,
													Object [ ] args )
	{
		IHealthDao healthDao =
            ( IHealthDao ) this
                               .getDao ( IHealth.class ) ;
		return healthDao.findByNamedQuery ( queryName , args ) ;
	}

	@ Override
	public String [ ] modifyHealth (
										Object [ ] health )
	{



		if ( null == health)
		{
			return null ;
		}
		
		else
		{
		
			IHealthDao healthDao =
			                       ( IHealthDao ) this
			                                          .getDao ( IHealth.class ) ;

			Health[] healths=new Health[health.length];
						for(int i=0;i<health.length;i++)
						{
							Health health2=( Health ) health[i];
							healths[i]=health2;
						}
						return healthDao
						                .merge  ( healths ) ;
			
		}
	
	
	
	}

}
